local ClientOHOH = _G.ClientOHOH;
local M = ClientOHOH.class.new(script, ClientOHOH.files.BaseComponent(),script.Parent.Name);
local ContextActionService = game:GetService("ContextActionService")
local LanguageHelper=_G.LanguageHelper --1:购买，2装备，3卸载
local GlobalTipGui = ClientOHOH.load.UIManager().ui_list.GlobalTipGui;
local Pet_Cfg=ClientOHOH.config.Pet
local Game_Cfg=ClientOHOH.config.Game
local PetTool=_G.CommonOHOH.load.PetTool();
local FunctionList = ClientOHOH.load.FunctionList();



local GoldenPetGui = ClientOHOH.load.UIManager().ui_list.PetGoldGui

function M.new(self,...)
	return M(self,...);
end;

function M.ctor(self, parent)
	M.super.ctor(self, parent);

    self.player=self.parent
    self.DataBase=self.parent:GetComponent(ClientOHOH.load.Client_PlayerDataComponent());
    ------------黄金宠物--------------------
    GoldenPetGui:SetDataBase(self.DataBase)
    self:UpdateProbability()

    GoldenPetGui.BuyEvent:Connect(function(data)
        self.player.RobuxBuyEvent:Action(data.gid,data.gType)
    end)
    self.parent.UserDataEvent:Connect(function(data)
        if data["pets"] then
            GoldenPetGui:UpdateListGui()
        end
        if data["gamePass"] then
            for index, _ in data["gamePass"] do
                if index == "gamepass_make_gold" then
                    -- print("have")

                    self:AddProcess(function()
                        task.wait(0.1)
                        self:UpdateProbability()
                        GoldenPetGui.gamepassBuyDoneEvent:Action()
                    end)

                end
            end
        end
    end)

    GoldenPetGui.MakeEvent:Connect(function(petId,count)
        local success = self.parent:Invoke(FunctionList.gold_craft,petId,count)
        return success
    end)
end


function M.UpdateProbability(self)
    local count = PetTool.GetMakeGoldMaxCount(self.player)
    local prob = 100/count
    GoldenPetGui:SetMakeProbability(prob)
end


function M.dtor(self)
	M.super.dtor(self);
end

return M

